import java.io.IOException;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

public class HttpPostUtils {
	private static Logger logger = Logger.getLogger(HttpPostUtils.class);
	public static String postData(String uri,HttpParams params){
		HttpPost post = new HttpPost(uri);
		post.setParams(params);
		HttpResponse response;
		com.alibaba.fastjson.JSONObject json = null;
		String state = null;
		try {
			HttpClient client = new DefaultHttpClient();
	/*		client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000);
			client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,5000);*/
			response = client.execute(post);
			HttpEntity entity = response.getEntity();
			String res = EntityUtils.toString(entity);
			if(res == null){
				logger.info("未获取到返回数据,推送失败!");
			}else{
//				json = new JSONObject(res);
				try {
					json = com.alibaba.fastjson.JSONObject.parseObject(String.valueOf(res));
				} catch (Exception e) {
//			LOG.error(ExceptionUtils.getFullStackTrace(e));
				}
				state = json.getString("status");
			}
		} catch (ClientProtocolException e) {
			logger.error("远程服务连接异常:"+e.getMessage());
		} catch (IOException e) {
			logger.error("返回数据处理异常:"+e.getMessage());
		}catch (JSONException e) {
			logger.error("未获取到返回信息字段:"+e.getMessage());
		}
		return state;
	}
}
